home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Magazine / Online / httpproxy / src / cache.h < prev    next >
C/C++ Source or Header  |  1996-08-20  |  5KB  |  127 lines

  1. /*(( "Header" */
  2. /*
  3.  * $Id: cache.h,v 1.3 1996/08/12 03:33:36 mshopf Exp mshopf $
  4.  *
  5.  * (c) 1995-96 Matthias Hopf
  6.  *
  7.  * Cache file maintainance for HttpProxy.
  8.  *
  9.  */
  10.  
  11. /*
  12.  * $Log: cache.h,v $
  13.  * Revision 1.3  1996/08/12  03:33:36  mshopf
  14.  * return (7) for CacheRemove explained.
  15.  *
  16.  * Revision 1.2  1996/07/30  13:57:03  mshopf
  17.  * clean up.
  18.  *
  19.  * Revision 1.1  1996/07/17  16:42:42  mshopf
  20.  * Initial revision
  21.  *
  22.  */
  23.  
  24.  
  25. /*)) */
  26.  
  27. #ifndef _CACHE_H__
  28. #define _CACHE_H__
  29.  
  30.  
  31. /*(( "Includes" */
  32.  
  33. #include <exec/types.h>
  34. #include <dos.h>
  35.  
  36. /*)) */
  37. /*(( "Constants" */
  38.  
  39. #define CACHEDIRVALIDFILE "@dirurl"    /* Checkfile for valid directories */
  40. #define MAX_FILE_DEPTH 8        /* Maximum hirarchy depth */
  41.  
  42. /* all lengths include trailing '0' byte */
  43.  
  44. #define MAX_FILE_LEN   32       /* Maximum filename length */
  45. #define MAX_PATH_LEN   128      /* Maximum total path length (dir+file) */
  46. #define MAX_TEMP_LEN   20       /* Maximum size of temporary files (including dir), e.g. @request/013cab02 */
  47.  
  48. /*)) */
  49. /*(( "Types" */
  50.  
  51. /* !!! still hacky... to be revised! */
  52. struct _request; /* can't predefine request_t... */
  53.  
  54. typedef struct {
  55.            struct _request *Req;
  56.            BPTR File;                                /* != null when no file is open */
  57.            char FileName [MAX_PATH_LEN];             /* the final filename (PUBLIC) */
  58.            char TempName [MAX_TEMP_LEN];             /* is "" when no temporary file was needed */
  59.            struct DateStamp Date;                    /* file timestamp */
  60.            } cachefile_t;
  61.  
  62. /*)) */
  63. /*(( "Prototypes" */
  64.  
  65. /* Initialisation routine. Clean up temporary cache directories. */
  66. /* return 0 on major failure */
  67. int   CacheInit (void);
  68.  
  69. /* Clean up. Called after last cache transaction. No open cache files should exists any more when calling this function. */
  70. /* May be called multiple times. */
  71. void  CacheExit (void);
  72.  
  73. /* Get cache information about a Url. cachefile_t *Cache will be filled for CacheOpen*.
  74.  * Missing directories are created, ambiguity is checked, temporary filenames are chosen.
  75.  * Returns 0 on no cache existing, 1 on valid cache, -1 on failure (can't create directory /
  76.  * double hash error...). Errors are logged.
  77.  * 'Date' is valid when a cache file already exists (return value 1). */
  78. // TODO: function for cache expire tests
  79. /* The Cache *must* always be invalidated by CacheClose before reusing! Even when this call
  80.  * returned -1! */
  81. int   CacheGet (cachefile_t *Cache, const char *Url, struct _request *Req);
  82.  
  83. /* Open an existing cache file. TempName is cleared. */
  84. /* Returns -1 on failure. Errors are logged. */
  85. int   CacheOpenOld (cachefile_t *Cache);
  86.  
  87. /* Open a new cache file. Url is needed for hash url files... */
  88. /* Returns -1 on failure. Errors are logged. */
  89. int   CacheOpenNew (cachefile_t *Cache, const char *Url);
  90.  
  91. /* Close file, invalidate cache struct, rename file when needed.
  92.  * Removes cache file on failure (ok = false = 0). Errors are logged. */
  93. void  CacheClose (cachefile_t *Cache, int Ok);
  94.  
  95. /* Read something from cache file (see Read()) */
  96. int  CacheRead (cachefile_t *Cache, void *Buffer, int Len);
  97.  
  98. /* Write something into cache file (see Write()) */
  99. int  CacheWrite (cachefile_t *Cache, const void *Buffer, int Len);
  100.  
  101.  
  102. /* The following support functions may be called from any directory level and without
  103.  * module initialisation. No external modules are called here. */
  104.  
  105. /* Get Url name from cache file into Url buffer. Return 0 on failure and on special files. */
  106. int  CacheResolve (const char *File, char *Url);
  107.  
  108. /* Delete cache file / Check cache file state. */
  109. /* returns 1 on success, 2 on invocation on non-deletable special files for directory managment
  110.  * (will be deleted by CacheRemoveDir()), 3 on invocation on strange files, 4 on non-existent
  111.  * files, 5 on related files (related to other cache files), 6 on special non-deletable files,
  112.  * 7 on strange files that should *really* be deleted (hash files without url files and vice versa)
  113.  * and 0 on delete errors. Check only the file status on DoDelete == FALSE, perhaps not touching
  114.  * the file at all (4 might not be returned). */
  115. /* will return the same values on DoDelete=false as on DoDelete=true */
  116. int  CacheRemove (const char *File, int DoDelete);
  117.  
  118. /* Delete cache dir (special files inside dirs, too). Check only whether the directory should be
  119.  * scanned on DoDelete == FALSE. */
  120. /* returns 1 on success, 2 on special directorys, 0 on delete failure. */
  121. /* will not always return the same values on DoDelete=false as on DoDelete=true!!! */
  122. int  CacheRemoveDir (const char *Dir, int DoDelete);
  123.  
  124. /*)) */
  125.  
  126. #endif /* _CACHE_H__ */
  127.